package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.ProductCatalog;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductCatalogService;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by mycp
 * @Classname ProductCatalogsController
 * @Description TODO 商品分类处理器
 * @Date 2018/11/15 1:14
 */
@RestController
@RequestMapping("/productCatalogs")
public class ProductCatalogsController {
    @Autowired
    private IProductCatalogService productCatalogService;

    @Autowired
    private IProductService productService;

    /**
     * 获取所有上架的商品分类信息
     */
    @GetMapping
    public Object getCatalogs(@RequestParam Long state){
        List<ProductCatalog> catalogs = productCatalogService.getCatalogs(state);
        return catalogs;
    }


    /**
     * 获取所有分类对应的商品
     * @return
     */
    @GetMapping("/products")
    public Object getProducts(QueryObject qo){
        PageInfo pageInfo = productCatalogService.getProducts(qo);
        return pageInfo;
    }

    /**
     * 获取指定的商品信息
     * 参数: productId = xx
     */
    @GetMapping("/products/{productId}")
    public Object getProductById(@PathVariable Long productId){
        Product product = productService.getProductById(productId);
        return product;
    }

    /**
     * 获取指定商品信息的详细介绍
     * @param productId
     * @return
     */
    @GetMapping("/products/{productId}/content")
    public Object getProductContentById(@PathVariable Long productId){
        return productService.getContentById(productId);
    }

    /**
     * 获取指定商品分类的 所有积分商品
     * @param catalogId
     * @return
     */
    @GetMapping("/{catalogId}/products")
    public Object getProductsByCatalogId(@PathVariable Long catalogId){
        List<Product> list = productService.getProductsByCatalogId(catalogId);
        return list;
    }

}
